function [value,flag,tree]=retreat_tree(s_hat,tree,i)

theta=[0 pi];
s_try=exp(j*theta);
b=bpsk2bin(s_hat(i));
index=b(1)+1;
tree(i,index)=0;
alternatives=find(tree(i,:)==1);
if(length(alternatives)>1)
	flag=1;
	value=s_try(alternatives(ceil(rand*length(alternatives))));
elseif(length(alternatives)>0)
	flag=1;
	value=s_try(alternatives);
else
	flag=0;
	value=0;
end
